大自然中最常见的生态之一,到了游戏里怎么就这么难做?
// Suppose Y is the point up to X. YIndex = XIndex + (0, 1);
float XHeight = WaterPreHeight.Load(XIndex).x;
float YHeight = WaterPreHeight.Load(YIndex).x;
if (IsBoundary(YHeight))
{
YHeight = XHeight;
}
if(bIsBoundary)
{
WaterHeight[SimulationIndex] = BOUNDARY_HEIGHT;
}
else
{
CapturedDepthVal = saturate(CapturedDepthVal);
float CurrentWaterHeight = WaterHeight[SimulationIndex];
// Object depth above water has no effect
WaterHeight[SimulationIndex] = CapturedDepthVal == 0.0f ? CurrentWaterHeight : min(CurrentWaterHeight, - CapturedDepthVal);
}
// Boundary pixels.
if(IsBoundary(PrevHeight))
{
// Skip iteration.
return;
}
// SWE
float NearHeight = UpPrevHeight + DownPrevHeight + LeftPrevHeight + RightPrevHeight;
float OutHeight = Damping * (PrevHeight + (PrevHeight - PrevPrevHeight) + TravelSpeed * 0.5f * (NearHeight - PrevHeight * 4));
// Store to output texture
OutWaterHeight[CurrentIndex] = OutHeight;
ERasterizerCullMode MeshCullMode = ComputeMeshCullMode(MaterialResource, OverrideSettings);
// Always render back faces
MeshCullMode = MeshCullMode == CM_CCW ? CM_CW : CM_CCW;
BuildMeshDrawCommmands(
...,
MeshCullMode,
...
);
// CustomCapturePS.usf
// Clip using water level, water level is already converted to device Z
clip(WaterLevelVal - SvPosition.z);